<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/js/axios.min.js"></script>
    <script src="/js/query.js"></script>
    <script>
        var productId;
        window.onload = function (){
            productId = getQuery("id");
            findProduct();
        }
        function findProduct(){
            axios.get("/product/findById",{
                params:{
                    id:productId
                }
            }).then(resp=>{
                var info=resp.data;
                $("img").src="/img/"+info.imgPath;
                $("name").innerHTML=info.name
                $("price").innerHTML=info.price
                $("speakNUm").innerHTML=info.speakNUm
                this.fullTable(info.speakBeans)
            })
        }
        function fullTable(speakList) {
            var str="";
            speakList.forEach(n =>{
                str += `<tr><td>${n.userBean.nickname}</td><td>${n.content}</td></tr>`;
            });
            $("data").innerHTML = str;
        }
        function addSpeak(){
            axios.get("/speak/add",{
                params: {
                    productId,
                    content:$("content").value
                }
            }).then(resp=>{
                let info= resp.data;
               if (info=="noland"){
                   location.href="/login.html"
               }else {
                   fullTable(info)
               }
            })
        }
    </script>
</head>
<body>
<div>
    <img src="" alt="" width="200" height="100" id="img"><br>
    商品名：<span id="name"></span><br>
    单价：<span id="price"></span><br>
    评论：<span id="speakNUm"></span><br>
    <table width="50%" border="1">
        <tbody id="data"></tbody>
    </table>
    请输入评价<input type="text" id="content">
    <input type="button" value="评论" onclick="addSpeak()">
</div>
</body>
</html>